package ArithmeticObjects;

import utils.ByteTree;

/**
 * Representing an array of arithmetic objects of the same type
 * @author Idan
 */
public abstract class ElementArray{
	
	/**
	 * @return the ByteTree representing the array of elements
	 * @throws Exception 
	 */
	public abstract ByteTree getByteTree() throws Exception;

	
	/**
	 * @param i the index of the required element in the array
	 * @return the element in the i'th position in the array
	 */
	public abstract Element getElementForIndex(int i);
	
	/**
	 * adds an element to the current array
	 * @param e the element to add to the array
	 * @throws Exception in case the element failed to be added to the array
	 */
	public abstract void addElement(Element e) throws Exception;
	
	/**
	 * @return the number of elements in the array
	 */
	public abstract int getArraySize();
	
	/**
	 * compares an ElementArray to another ElementArray
	 * @param e an ElementArray to compare to
	 * @return 0 if the ElementArrays are the same and 1 otherwise
	 * @throws Exception in case the comparison failed
	 */
	public int compareTo(ElementArray e) throws Exception{
		for (int i=0; i<this.getArraySize(); i++)
			if (this.getElementForIndex(i).compareTo(e.getElementForIndex(i)) != 0)
				return 1;
		return 0;
	}
	
	/**
	 * creates an ElementArray whose elements are the product of the current instance and 
	 * the given ElementArray arr element wise
	 * @param arr the ElementArray to multiply by
	 * @return an ElementArray whose elements are the product of the current instance and 
	 * the given ElementArray arr element wise
	 * @throws Exception if the multiplication fails
	 */
	public abstract ElementArray arrayMultiply(ElementArray arr) throws Exception;
	
	/**
	 * returns the string representation of the array
	 */
	public abstract String toString();
}